//
//  UserInfoModel.m
//  quxiangtao
//
//  Created by xbmios on 2018/9/25.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "UserInfoModel.h"
#import "NSData+Base64.h"

@implementation UserInfoModel

+ (void)getUserInfoWithPar:(NSString *)par succes:(HttpRequestSuccess)successBlock failBlock:(HttpRequestFailed)failBlock {
    
    [PPNetworkHelper POST:@"user/login/userinfo" parameters:@{@"json" : par} success:^(id responseObject) {
        
        NSLog(@"获取用户信息user/login/userinfo%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] == 1) {

            UserInfoModel *model = [UserInfoModel mj_objectWithKeyValues:responseObject[@"data"]];
            
//            NSData *photo = [NSData base64DataFromString:model.user_photo];
//
//            UIImage *image = [UIImage imageWithData:photo];
            
//            NSLog(@"base64string:\n%@\n头像：====\n%@", model.user_photo, photo);
            
            
            
            [CommonUserInfo sharedInstance].userInfoModel = model;
            [CommonUserInfo sharedInstance].isLogin = YES;
            
            [CommonUserInfo sharedInstance].is_setPayPassword = [model.is_paypass boolValue];
            [CommonUserInfo sharedInstance].phone = model.user_mobile;
            [CommonUserInfo sharedInstance].VIPLevel = model.vip;
            [CommonUserInfo sharedInstance].is_Bind = [model.is_bank boolValue];
            [CommonUserInfo sharedInstance].nickName = model.user_name;
            [CommonUserInfo sharedInstance].balance = model.user_money;
            [CommonUserInfo sharedInstance].photoUrl = model.user_photo;
//            [CommonUserInfo sharedInstance].iconIV = image;
            [CommonUserInfo sharedInstance].beanNum = model.user_bean;
            [CommonUserInfo sharedInstance].user_id = model.user_id;
            [CommonUserInfo sharedInstance].token = model.token;
            [CommonUserInfo sharedInstance].user_type = model.user_type;
            [CommonUserInfo sharedInstance].lv = model.lv;
            [CommonUserInfo sharedInstance].bean_quota = model.bean_quota;

            [CommonUserInfo sharedInstance].userInfoModel = model;
            
            
            if (successBlock) {
                
                successBlock(model);
            }
            
        }else {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
        }
        
    } failure:^(NSError *error) {
        
        if (failBlock) {
            
            failBlock(error);
            
        }
        
    }];
    
    
}

@end
